// router.ts
import { createRouter, createWebHistory, RouteRecordRaw, RouteLocationNormalized, NavigationGuardNext } from 'vue-router';
import Home from '../layout/index.vue'
import Section from '../layout/componets/section.vue'
import List1 from '../components/list1.vue'
import Board from '../components/home/board.vue'
import Table from '../components/vab/table.vue'
const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Layout',
        component: Home,
        children:[
            {
                path:'/home',
                name:'Home',
                component:Section,
                children:[
                    {
                        path:'/home/index',
                        name:'Index',
                        component:Board,
                        meta:{
                            title: "首页"
                        }
                    },
                    {
                        path:'board',
                        name:'Board',
                        component:List1,
                        meta:{
                            title: "看板"
                        }
                    }
                ]
            },
            {
                path:'/vab',
                name:'Vab',
                component:Section,
                children:[
                    {
                        path:'table',
                        name:'Table',
                        component:Table,
                        meta:{
                            title: "表格"
                        }
                    },
                    {
                        path:'board',
                        name:'Board1',
                        component:List1,
                        meta:{
                            title: "今日统计数据"
                        }
                    }
                ]
            }
        ]
    },

];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

// 前置路由
router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
    console.log('to', to)
    console.log('from', from)
    next()
})

// 路由跳转错误
router.onError(error => {
    console.warn("路由错误", error.message);
})

// 后置路由
router.afterEach((to: RouteLocationNormalized, from: RouteLocationNormalized) => {
    console.log('to', to)
    console.log('from', from)
})

export default router;